package com.zwk.edu.controller.front;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zwk.base.entity.CommonResult;
import com.zwk.base.util.JwtUtils;
import com.zwk.edu.client.MemberClient;
import com.zwk.edu.entity.Comment;
import com.zwk.edu.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author zwk
 * @since 2022-08-31
 */
@RestController
@CrossOrigin
@RequestMapping("/edu/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 接受前端传来的评论数据, 通过token获取用户数据
    @PostMapping("/saveComment")
    public CommonResult saveComment(@RequestBody Comment comment, HttpServletRequest request){
        commentService.saveComment(comment, request);
        return CommonResult.ok();
    }

    // 根据课程id查询评论信息
    @GetMapping("/getCommentList/{id}/{current}/{limit}")
    public CommonResult getCommentList(@PathVariable("id") String id,
                                       @PathVariable("current") Integer current,
                                       @PathVariable("limit") Integer limit){
        Page<Comment> page = new Page<>(current, limit);
        Map<String, Object> map = commentService.getCommentPageList(id, page);
        return CommonResult.ok().data(map);
    }

}

